//
//  Pantalla3.m
//  Grues
//
//  Created by Miquel Viladomat on 17/10/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "Pantalla3.h"
#import "ZonaBlavaAppDelegate.h"
#import "LlistaMotius.h"
#import "LlistaMarques.h"
#import "LlistaColors.h"
@implementation Pantalla3
@synthesize marca;
@synthesize model;
@synthesize matricula;
@synthesize motiu;
@synthesize color;
@synthesize situacio;
@synthesize llistamarques=_llistamarques;
@synthesize llistamotius=_llistamotius;
@synthesize llistacolors=_llistacolors;
@synthesize quadrecolor;
@synthesize logomarca;



-(IBAction)dismiss{
    [self resignFirstResponder];
}

-(IBAction)esborrar{
    UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"" message:@"Aquesta acció esborrarà totes les dades i no es pot desfer." delegate:self cancelButtonTitle:@"Conservar" otherButtonTitles:@"Eliminar", nil ];
    
    [message show];
    
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
    
    if([title isEqualToString:@"Eliminar"])
    {
        ZonaBlavaAppDelegate *dataCenter=(ZonaBlavaAppDelegate *)[[UIApplication sharedApplication] delegate];
        dataCenter.marcav=@"";
        dataCenter.modelv=@"";
        dataCenter.colorv=@"";
        dataCenter.matriculav=@"";
        dataCenter.motiuv=@"";
        marca.text=@"";
        model.text=@"";
        color.text=@"";
        matricula.text=@"";
        motiu.text=@"";
        
    }
    
}
-(IBAction) canvitext{
    ZonaBlavaAppDelegate *dataCenter=(ZonaBlavaAppDelegate *)[[UIApplication sharedApplication] delegate];
    dataCenter.marcav=marca.text;
    dataCenter.modelv=model.text; 
    dataCenter.colorv=color.text;
    dataCenter.matriculav=matricula.text;
    dataCenter.matriculav=matricula.text;
    dataCenter.motiuv=motiu.text;
    dataCenter.posicio2v=situacio.text;
    //NSLog(dataCenter.posiciov);
}

-(IBAction)triamotiu{
    LlistaMotius *llistaViewController=[[LlistaMotius alloc] initWithNibName:@"LlistaMotius" bundle:nil];
    [self presentModalViewController:llistaViewController animated:YES];
}
-(IBAction)triamarca{
    LlistaMarques *llistaViewController=[[LlistaMarques alloc] initWithNibName:@"LlistaMarques" bundle:nil];
    [self presentModalViewController:llistaViewController animated:YES];
}
-(IBAction)triacolor{
    LlistaColors *llistaViewController=[[LlistaColors alloc] initWithNibName:@"LlistaColors" bundle:nil];
    [self presentModalViewController:llistaViewController animated:YES];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
    
    
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
   [quadrecolor setEnabled:NO];
    [quadrecolor setBackgroundColor:[UIColor blackColor]];

    
    //Pantalla2 *temp=[[Pantalla2 alloc]initWithNibName:@"Pantalla2" bundle:[NSBundle mainBundle]];
   // self.pant2=temp;
   // [temp release];
   // [self.navigationController pushViewController:self.pant2 animated:YES];
    // Do any additional setup after loading the view from its nib.
    ZonaBlavaAppDelegate *dataCenter=(ZonaBlavaAppDelegate *)[[UIApplication sharedApplication] delegate];
    [situacio setText:dataCenter.posiciov];
    dataCenter.posicio2v=dataCenter.posiciov;
}
-(void)viewWillAppear:(BOOL)animated{
    ZonaBlavaAppDelegate *dataCenter=(ZonaBlavaAppDelegate *)[[UIApplication sharedApplication] delegate];
    marca.text=dataCenter.marcav;
    model.text=dataCenter.modelv;
    color.text=dataCenter.colorv;
    matricula.text=dataCenter.matriculav;
    motiu.text=dataCenter.motiuv;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
